#include "stdafx.h"

#include "..\switches.h"

namespace Fast
{

TESTCLASS(SwitchesTests)
{
	CString dll, shortName;

	virtual void ClassInitialize()
	{
		::GetModuleFileName(_AtlBaseModule.GetModuleInstance(), dll.GetBuffer(MAX_PATH), MAX_PATH);
		dll.ReleaseBuffer();

		::GetShortPathName(dll, shortName.GetBuffer(MAX_PATH), MAX_PATH);
		shortName.ReleaseBuffer();
	}

	TESTMETHOD(IsSingleDllModeTest)
	{
		Switches switches(L"some.exe " + shortName);
		TDD_VERIFY(true == switches.IsSingleDllMode());
	}
	TESTMETHOD(IsSingleDllModeWithNoDll)
	{
		Switches switches(L"some.exe ");
		TDD_VERIFY(false == switches.IsSingleDllMode());
	}
	TESTMETHOD(IsSingleDllModeWithDoubleQuotedExe)
	{
		Switches switches(L"\"some.exe\" " + shortName);
		TDD_VERIFY(true == switches.IsSingleDllMode());
	}
	TESTMETHOD(IsSingleDllModeWithDoubleQuotedDll)
	{
		Switches switches(L"\"some.exe\" \"" + dll + L"\"");
		TDD_VERIFY(true == switches.IsSingleDllMode());
	}
	TESTMETHOD(MalformedIsSingleDllModeTest)
	{
		Switches switches(L"\"some.exe\" \"" + dll); // N.B.:  no closing quote
		TDD_VERIFY(true == switches.IsSingleDllMode());
	}

	TESTMETHOD(IsSingleDllModeWithoutDoubleQuotedExe)
	{
		Switches switches(L"objc\\i386\\some.exe " + shortName);
		TddAssert().IsTrue(switches.IsSingleDllMode(), L"no quotes on exe works");
	}
	TESTMETHOD(WackyVistaTestWithTwoConsecutiveSpaces)
	{
		Switches switches(L"objc\\i386\\some.exe  " + shortName);
		TddAssert().IsTrue(switches.IsSingleDllMode(), L"two spaces in a row works");
	}

	TESTMETHOD(IsDumpModeTest)
	{
		Switches switches(L"\"some.exe\" \"" + dll + L"\" -?");
		TDD_VERIFY(true == switches.IsDumpMode());
	}
	TESTMETHOD(DumpModeButNoDll)
	{
		Switches switches(L"some.exe -?");
		TDD_VERIFY(false == switches.IsDumpMode());

		Switches switches2(L"\"some.exe\" -?");
		TDD_VERIFY(false == switches2.IsDumpMode());
	}

	TESTMETHOD(IsRecursiveModeTest)
	{
		CPath path(dll);
		path.RemoveFileSpec();

		Switches switches(L"\"some.exe\" \"" + CString(path) + L"\"");
		TDD_VERIFY(true == switches.IsRecursiveMode());
	}
};

}
